/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.employee.controller;

import com.admin.model.EmployeeFacadeLocal;
import com.entities.Employee;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Chung
 */
@Stateless
public class EmployeeBean implements EmployeeBeanRemote {
   
    private EmployeeFacadeLocal getRemote(){
        try {
            InitialContext ictx = new InitialContext();
            EmployeeFacadeLocal remote = (EmployeeFacadeLocal) ictx.lookup("java:global/BluePumpkinEJB/EmployeeFacade!com.admin.model.EmployeeFacadeLocal");
            return remote;
        } catch (NamingException ex) {
            Logger.getLogger(EmployeeBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    @Override
    public String loginControl(String username, String password) { 
        EmployeeFacadeLocal remote = getRemote();
        Employee em = remote.find(username);
        if(em != null){
            if(em.getPassword().equals(password)){
                return em.getFullname();
            }
        }
        return null;
    }

   
}
